home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tools4c.arc / MANUAL.TXT < prev    next >
Text File  |  1988-12-27  |  45KB  |  922 lines

  1.  
  2.  
  3.  
  4.                                                                       
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                                 TOOLS FOR C
  14.                        Application Development Package
  15.                                 USERS MANUAL
  16.  
  17.  
  18.                       Shareware Distribution Version 1.0
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.          This version of TOOLS FOR C and it's associated manuals and
  27.          support files may be freely copied and distributed as long as
  28.          it is distributed in it's entirety and no fees other than
  29.          nominal handling fees are charged.  The routines in this
  30.          library are NOT Public Domain.  This is copyrighted material. 
  31.          The intent behind distributing this version of TOOLS FOR C is
  32.          to allow you to use the package on a trial basis and determine
  33.          if it meets your needs.  If you find yourself using this
  34.          package, you MUST register by sending $45.00 to the address
  35.          listed below.  Upon receipt of your registration fee we will
  36.          send you an expanded manual, compiled libraries for all of the
  37.          memory models available with your compiler, and the complete
  38.          source code to the library. In NO EVENT may you use any of the
  39.          routines in TOOLS FOR C for commercial purposes until you
  40.          register your copy.  We feel that you will find the value of
  41.          TOOLS FOR C far exceeds the registration fee and we at BP
  42.          SOFTWARE SOLUTIONS, INC. thank you in advance for your
  43.          support.
  44.  
  45.  
  46.  
  47.  
  48.  
  49.                         BP Software Solutions, Inc.
  50.                         642 N. Commodore Drive
  51.                         Plantation, Fl.  33325
  52.  
  53.  
  54.  
  55.  
  56.  
  57.                                           Copyright (C) 1987 
  58.                                                 BP Software Solutions Inc.
  59.                                                        All Rights Reserved
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.                               Table of Contents
  73.  
  74.  
  75.  
  76.  
  77.  
  78.                 INTRODUCTION . . . . . . . . . . . . . . .    3
  79.                      The Manual. . . . . . . . . . . . . .    3
  80.                      Concerning Compiling. . . . . . . . .    3
  81.  
  82.                 VIDEO  . . . . . . . . . . . . . . . . . .    4
  83.                      Video Routines  . . . . . . . . . . .    4
  84.                      Video Attributes  . . . . . . . . . .    4
  85.                      Cursor Control  . . . . . . . . . . .    5
  86.                      Character Output  . . . . . . . . . .    5
  87.                      String Output . . . . . . . . . . . .    6
  88.                      Screen Scrolling  . . . . . . . . . .    6
  89.  
  90.                 KEYBOARD . . . . . . . . . . . . . . . . .    7
  91.                      Keyboard Routines . . . . . . . . . .    7
  92.                      KEY.H . . . . . . . . . . . . . . . .    7
  93.  
  94.                 WINDOWS  . . . . . . . . . . . . . . . . .    8
  95.                      Creating windows  . . . . . . . . . .    8
  96.                      Menugen.Exe . . . . . . . . . . . . .   10
  97.                      Window Management . . . . . . . . . .   10
  98.                      Closing Windows . . . . . . . . . . .   11
  99.  
  100.                 MENUS  . . . . . . . . . . . . . . . . . .   13
  101.                      Creating Menus  . . . . . . . . . . .   13
  102.                      Menugen . . . . . . . . . . . . . . .   13
  103.                      Menu Selections . . . . . . . . . . .   13
  104.                      Error Handling  . . . . . . . . . . .   14
  105.                      menu_text() . . . . . . . . . . . . .   14
  106.                      Titling Menus . . . . . . . . . . . .   14
  107.                      Menu Structures . . . . . . . . . . .   15
  108.  
  109.                 GLOBAL VARIABLES . . . . . . . . . . . . .   16
  110.  
  111.                 INDEX  . . . . . . . . . . . . . . . . . .   18
  112.  
  113.  
  114.  
  115.  
  116.                                                                      page 3
  117.                               INTRODUCTION
  118.  
  119.  
  120.      Introduction
  121.  
  122.           TOOLS FOR C provides a comprehensive library of tested C and
  123.           assembler functions to complement the standard library provided
  124.           with your C compiler.  You will find routines for screen and
  125.           keyboard I/O, window management, a menu system, string routines
  126.           and more.  Included in the shareware distribution version are
  127.           compiled libraries for linking with the small memory models
  128.           of Microsoft C (R) v4.0,  Lattice C (R) v3.x, and Borland
  129.           International's Turbo C (R) v 1.0.  Upon receipt of your
  130.           registration fee, we will send you the libraries for the all of
  131.           the memory models supported by your compiler and the complete C
  132.           and assembler source code.  You will then be able to modify any
  133.           of the routines which do not precisely meet your needs. 
  134.           Furthermore, you will be able to recompile the library using
  135.           different optimization flags, different function naming
  136.           conventions, or for that matter, a different compiler
  137.           altogether.
  138.  
  139.      The Manual
  140.  
  141.           The manual is organized into chapters, each dealing with one
  142.           subgroup of routines.  The first chapter, video, describes the
  143.           functions dealing with screen output.  Keyboard deals with the
  144.           key() function and the macro keystroke definitions provided with
  145.           the package.  The third and fourth chapters describe the many
  146.           functions and capabilities of the window and menu management
  147.           routines in TOOLS FOR C.  A detailed explanation of each control
  148.           structure is given.
  149.  
  150.           The large reference section details each function, giving
  151.           specific calling requirements and examples.  The function
  152.           reference section is a comprehensive description of each Turbo
  153.           Library routine.  Each routine is listed with it's function
  154.           name, synopsis, a detailed description, and return values if any.
  155.  
  156.      Concerning Compiling
  157.  
  158.           When we developed TOOLS FOR C we chose long, descriptive names
  159.           for the functions.  This avoids the cryptographer's delight that
  160.           results from trying to name too many functions with too few
  161.           characters. Therefore, when compiling programs to be linked with
  162.           TOOLS FOR C you must be sure to use the compiler option
  163.           activating long identifier names.  In Lattice C (R) this is the
  164.           -n flag, in Microsoft C (R) and Turbo C (R) long names are the
  165.           default.  The header file TOOLS4C.H should be included in all
  166.           source code which uses TOOLS FOR C.  MENU.H is necessary in any
  167.           code which references the menu() function.  KEY.H can be included
  168.           as an aid in defining the codes returned by key(), but it's use
  169.           is not required.  The library does not replace any of the
  170.           standard library functions, so link order is not important.
  171.  
  172.  
  173.                                                                      page 4
  174.                                   VIDEO
  175.  
  176.       
  177.      Video Routines
  178.  
  179.           The video routines provided in the library allow direct hardware
  180.           control of Color Graphic Adapters and Monochrome Adapters,
  181.           bypassing most of the DOS and BIOS routines.  This allows for
  182.           much greater display speed and far more flexibility.  Direct
  183.           hardware control requires that the routines be informed of which
  184.           adapter is installed.  This is accomplished by calling the
  185.           function "vid_type()" which sets a couple of global integer
  186.           variables (_vid_buf and _vid_type).  A hardware dependent
  187.           routine can check these to tell which type of adapter is
  188.           presently being used.  This function must be called at least
  189.           once before any of the video routines are called.  If it is not,
  190.           a monochrome adapter will be assumed. While direct hardware
  191.           control is required for acceptable performance, it also
  192.           unfortunately requires a high degree of hardware compatibility
  193.           with IBM's CGA or Monochrome Adapter. Most PC compatible video
  194.           boards do closely match one of these adapters so running
  195.           applications developed using TOOLS FOR C on IBM compatible
  196.           computers should present no problems.  If you do experience
  197.           difficulties, minor changes to the library, using the supplied
  198.           source code, will probably solve your problem.  
  199.  
  200.           As explained below, control of the video attributes is left
  201.           entirely to you. In order to allow selection of monochrome or
  202.           color attributes at run time, vid_type() sets a global variable
  203.           "_color" to TRUE if the current video mode is 3 (80x25 color
  204.           text).  If the current video mode is 2 (80x25 B/W text) or 7
  205.           (Mono) then "_color" defaults to FALSE.  If the current video
  206.           mode is not set to one of these values, vid_type() returns ERROR
  207.           (-1) instead of OK (0).  The return value should be checked as
  208.           the TOOLS FOR C video routines are designed to operate only
  209.           with the video mode set to one of the eighty column text modes
  210.           (CO80, BW80 or MONO).  If there is any question as to which mode
  211.           the display is in, routines in the library allow you change it
  212.           and then return it to the old value before exiting.
  213.  
  214.        
  215.      Video Attributes
  216.  
  217.           Many of the routines require you to specify a video attribute. 
  218.           One of the basic decisions made during the design phase of the
  219.           library was to not implement video attributes as global variables,
  220.           but instead to require that they be passed each time as a
  221.           parameter.  Any additional work on the part of the programmer that
  222.           this approach requires will certainly be repaid in program
  223.           maintenance hours.  Two global variables are provided which are
  224.           set by the vid_type() routine which will allow you to determine
  225.           which type of video adapter is installed and whether or not the
  226.           color mode is set on a CGA in the event that you want to use
  227.           attributes which are not compatible across all modes.
  228.  
  229.  
  230.  
  231.      Cursor Control                                                  page 5
  232.  
  233.           Two different sets of cursor control routines are included which
  234.           provide essentially the same services but require or return
  235.           different parameters.  One set, curs() and get_curs(), specifies
  236.           the cursor location as an encoded integer where the high eight
  237.           bits defines the cursor row and the low eight bits defines the
  238.           cursor column.  The other set, cursor() and get_cursor(),
  239.           requires two separate integer variables, one each for the row
  240.           and column.  To set the cursor location, these are passed as
  241.           parameters, but since it is possible to return only one variable
  242.           from a C routine, to determine the cursor location it is
  243.           necessary to provide the address of two integer variables to
  244.           get_cursor().  get_cursor() then stuffs these variables with the
  245.           appropriate values.  
  246.  
  247.           If it is only necessary to save and restore the cursor location,
  248.           then get_curs() and curs() are much easier to use, but if you need
  249.           to determine the row or column, or set the cursor to a specific
  250.           location, then get_cursor() or cursor() will save some masking and
  251.           bit-shuffling.  
  252.  
  253.           Throughout the library, screen locations are defined in terms of
  254.           (column, row) with the upper left corner of the screen defined as
  255.           location (0,0). Columns are numbered from the left most column  0
  256.           to the right most column 79 and rows are numbered from the top 0
  257.           to the bottom 24.  The lower right screen location is (79,24).
  258.  
  259.           Programming note:  One way to remove the blinking cursor from
  260.           the screen, is to call cursor() with a set of screen coordinates
  261.           somewhere off the screen, such as cursor( 1, 25 ).  The blinking
  262.           hardware cursor will be hidden until another call is made to
  263.           cursor() with parameters within the visible area of the screen. 
  264.           Take care, however, that you do not use any write to screen
  265.           routines which write characters at the current cursor position
  266.           while the cursor is not visible for obvious reasons.
  267.  
  268.           There are three cursor shape control functions. The first,
  269.           cursor_type(), allows you to change the cursor to one of eight
  270.           different sizes or to blank it entirely depending on the
  271.           parameter passed to it. The other two, normal_cursor() and
  272.           block_cursor() set the cursor to the two most commonly used
  273.           shapes without the need to specify a parameter.
  274.  
  275.  
  276.      Character Output
  277.  
  278.           Numerous routines are provided for writing characters to the
  279.           screen. 
  280.  
  281.           write_tty(), write_a(), and write_ac() write to the current
  282.           cursor position.  write_tty() uses the bios write_as_tty
  283.           function and recognizes special characters like bell and
  284.           backspace.  write_ac() writes to the cursor position along with
  285.           a video attribute and advances the cursor.  write_a() does the
  286.           same without advancing the cursor.  
  287.  
  288.  
  289.                                      page 6
  290.  
  291.           write_am() writes multiple copies of the same character along with
  292.           a video attribute.
  293.  
  294.           write_al() writes a character and attribute to a specified screen
  295.           location without regard for the current cursor location.
  296.  
  297.      String Output
  298.  
  299.           Like the character output routines, there are several string
  300.           output routines available which allow writing strings to the
  301.           screen beginning at either the current cursor position or a
  302.           specified location.
  303.  
  304.           write_str() writes a string to screen beginning at the location
  305.           specified, without regard for the cursor, using the supplied
  306.           attribute.  No special characters are supported however, this is
  307.           the quickest routine.
  308.  
  309.           print_string() writes a string and attribute beginning at the
  310.           current cursor position and supports the special characters '\n'
  311.           '\t' and '\r'.  This routine is somewhat slower than write_str()
  312.           but much quicker than aprintf().
  313.  
  314.           aprintf() writes a formatted string to the screen using the
  315.           specified attribute.  All the printf() formatting codes and
  316.           control characters are supported.  In fact, because the
  317.           sprintf() or vprintf() function in the standard library is
  318.           called to do the formatting the only thing not supported is
  319.           output redirection.  Total string length is limited to 255
  320.           characters, however.
  321.  
  322.      Screen Scrolling
  323.  
  324.           scroll() provides an easy way to scroll any part of the screen
  325.           up or down. You supply the boundaries of the area to scroll, the
  326.           direction to scroll, the number of lines to scroll, and the
  327.           video attribute to use in filling the newly cleared area of the
  328.           screen.  Passing the routine a zero for the number of lines to
  329.           scroll will result in the entire area being blanked and filled
  330.           with the specified video attribute.
  331.  
  332.  
  333.  
  334.                                                                      page 7
  335.  
  336.                                KEYBOARD
  337.  
  338.  
  339.  
  340.      Keyboard Routines
  341.  
  342.           The library's keyboard I/O routines are designed to allow you to
  343.           easily interface a program to a computer that uses the IBM
  344.           PC/XT/AT Extended Ascii format.  A single call to key() is all
  345.           that is required to get the next keystroke and uniquely identify
  346.           it.  This is possible because key() returns and integer value
  347.           instead of a char value. Any returned value less than 256 (0x0100)
  348.           is a normal keyboard character, control character or a value
  349.           returned by using the ALT key in combination with the numeric
  350.           keypad.  If the returned value is 256 (0x0100) or higher, then one
  351.           of the function or special keys has been pressed and it's extended
  352.           code is in the upper two bytes.  In most cases you need not be
  353.           concerned with all of this as the return codes for most of the
  354.           special keys are defined in the include file KEY.h.  To determine
  355.           if a particular key has been pressed, just compare the returned
  356.           value with it's definition.
  357.  
  358.  
  359.      Listing of KEY.H
  360.  
  361.         #define TAB       0x0009                #define SFTTAB    0x0f00
  362.         #define RETURN    0x000d                #define ALT_F4    0x6b00
  363.         #define SPACE     0x0020                #define ALT_F5    0x6c00
  364.         #define UP        0x4800                #define ALT_F6    0x6d00
  365.         #define DOWN      0x5000                #define ALT_F7    0x6e00
  366.         #define LEFT      0x4b00                #define ALT_F8    0x6f00
  367.         #define RIGHT     0x4d00                #define ALT_F9    0x7000
  368.         #define HOME      0x4700                #define ALT_F10   0x7100
  369.         #define END       0x4f00                #define CNT_F1    0x5e00
  370.         #define PGUP      0x4900                #define CNT_F2    0x5f00
  371.         #define PGDN      0x5100                #define CNT_F3    0x6000
  372.         #define F1        0x3b00                #define CNT_F4    0x6100
  373.         #define F2        0x3c00                #define CNT_F5    0x6200
  374.         #define F3        0x3d00                #define CNT_F6    0x6300
  375.         #define F4        0x3e00                #define CNT_F7    0x6400
  376.         #define F5        0x3f00                #define CNT_F8    0x6500
  377.         #define F6        0x4000                #define CNT_F9    0x6600
  378.         #define F7        0x4100                #define CNT_F10   0x6700
  379.         #define F8        0x4200                #define SFT_F1    0x5400
  380.         #define F9        0x4300                #define SFT_F2    0x5500
  381.         #define F10       0x4400                #define SFT_F3    0x5600
  382.         #define ESC       0x001b                #define SFT_F4    0x5700
  383.         #define BKSP      0x0008                #define SFT_F5    0x5800
  384.         #define INS       0x5200                #define SFT_F6    0x5900
  385.         #define DEL       0x5300                #define SFT_F7    0x5a00
  386.         #define ALT_F1    0x6800                #define SFT_F8    0x5b00
  387.         #define ALT_F2    0x6900                #define SFT_F9    0x5c00
  388.         #define ALT_F3    0x6a00                #define SFT_F10   0x5d00
  389.  
  390.  
  391.  
  392.                                                                      page 8
  393.  
  394.                                    WINDOWS
  395.  
  396.  
  397.  
  398.      Turbo Library Windows 
  399.  
  400.           The functions in TOOLS FOR C allow you to quickly create
  401.           pop-up, overlapping windows for your own programs.  The contents
  402.           of the screen under each window is automatically saved when the
  403.           window is opened and restored when it is closed.  Windows can be
  404.           moved around the screen.  Overlaid windows can be brought to the
  405.           front or closed.  The routines will keep track of the saved video
  406.           so that when the last window is closed, the original screen will
  407.           be intact.  Video attributes of the border and the center fill
  408.           area can be specified.  Cursor or text in a window can be made
  409.           relative to the window position so that if you open a window in a
  410.           new position any text written to the window will remain in the
  411.           same place within the window.  You can select any characters you
  412.           like for the border.  Any character can be specified to fill the
  413.           area inside the window's borders.  
  414.  
  415.      Creating windows
  416.  
  417.           All of the parameters necessary to open a window are found in a
  418.           structure defined in TOOLS4C.H as a typedef "WNDW".  Below is the
  419.           listing as it appears in TOOLS4C.H with comments added.  
  420.  
  421.           typedef struct WNDW {
  422.                int  left_col_line_char;      /*   The next eight lines    */
  423.                int  upper_row_line_char;     /*   specify the characters  */
  424.                int  right_col_line_char;     /*   to be used for lines    */
  425.                int  lower_row_line_char;     /*   and corners of the      */
  426.                int  ulcorner_char;           /*   border                  */
  427.                int  urcorner_char;
  428.                int  llcorner_char;
  429.                int  lrcorner_char;
  430.                int  fill_char;     /* this char, normally a space, fills  */
  431.                                    /* the center of the window            */
  432.                int  line_attr;     /* this is the border video attribute  */
  433.                int  fill_attr;     /* this is the fill area video attrib. */
  434.                int  upper_row;     /* The next four lines define the      */
  435.                int  left_col;      /* boundary of the window. These are  */
  436.                int  lower_row;     /* the columns and rows where the      */
  437.                int  right_col;     /* border will be placed               */
  438.                int  curr_row;      /* an area to store the cursor         */
  439.                int  curr_col;      /* position for your own use, they are */
  440.                                    /* not used by the window functions    */
  441.                  /* The remaining structure members are filled in by   */
  442.                  /* the window management functions. You should define */
  443.                  /* them as zeros or NULLs, as appropriate.            */
  444.                int  buf_size;           /* size of the video buffer area  */
  445.                struct WNDW *prev_wndw;  /* pointer to previous window     */
  446.                struct WNDW *next_wndw;  /* pointer to next window         */
  447.                char      *image;        /* pointer to video buffer        */
  448.                } WNDW ; 
  449.  
  450.  
  451.                                                                      page 9
  452.  
  453.           To create a window, you need only to define a structure of type
  454.           WNDW initialized to the window's desired parameters.  You then
  455.           call open_window() or open_ex_window() with the address of this
  456.           window structure as an argument. See the example below.
  457.  
  458.  
  459.                struct WNDW head1 ={' ',' ',' ',' ',' ',' ',' ',' ',
  460.                          ' ',0xF,0x70,15,1,79,10,0,0,0,NULL,NULL,NULL};
  461.  
  462.                /*   The structure above defines a window with the upper left
  463.                     corner at 15,1 and the lower right corner at 79,10. The
  464.                     characters on the top line, just after the opening brace
  465.                     are the various border and corner characters.  The 
  466.                     blank space defined at the beginning of the first line
  467.                     is the character which will fill the interior of the
  468.                     window.   0xF is the border's video attribute.  0x70 is
  469.                     the window interior's video attribute.  The next four
  470.                     integers define the window's location on the screen. 
  471.                     The first two zeros are unused integer variables that
  472.                     are available for your use.  The final zero integer and
  473.                     three NULLs must be defined as shown.  These locations
  474.                     are filled in and manipulated by various window
  475.                     functions and should not be modified in any other way.  
  476.                          */
  477.  
  478.                int ret_code;
  479.  
  480.                     ret_code = open_window( &head1 );
  481.  
  482.                     if(ret_code == ERROR)
  483.                          printf("Error opening Window\n");
  484.  
  485.  
  486.           Alternatively, a pointer of type WNDW can be set equal to the
  487.           address  of the window structure.  This pointer can then be used
  488.           to call any of the window management functions which require the
  489.           structure address.
  490.  
  491.  
  492.                struct WNDW head1 ={' ',' ',' ',' ',' ',' ',' ',' ',
  493.                          ' ',0xF,0x70,15,1,79,10,0,0,0,NULL,NULL,NULL};
  494.  
  495.                int ret_code;
  496.                WNDW *wind3;
  497.  
  498.                     wind3 = &head1; 
  499.                     ret_code = open_ex_window( wind3 );
  500.  
  501.                     if(ret_code == ERROR)
  502.                          printf("Error opening Window\n");
  503.  
  504.           After attempting to open a window, the return code should be
  505.  
  506.  
  507.  
  508.                                                                      page 10
  509.  
  510.  
  511.           checked to see if the window was successfully opened. OK, defined
  512.           as zero in TOOLS4C.H is returned if successful, and ERROR, defined
  513.           as -1 is returned if the routine was not able to allocate memory
  514.           for the video buffer.  The only limit on the number of windows
  515.           which can be open is the memory available.  No checking is done
  516.           for bogus arguments in the structure definition.  
  517.  
  518.      Menugen.Exe
  519.  
  520.           Included in the TOOLS FOR C package is a program - MENUGEN.EXE -
  521.           which simplifies the definition of a window.  The program allows
  522.           you to "point and shoot" the borders of a window, then a series of
  523.           menus allow you to select various border and fill characters and
  524.           attributes and display them on the screen.  When you are satisfied
  525.           with the window, an output file is written which can be included
  526.           in your program.  A pointer to this window structure is also
  527.           defined in the file, so all that is necessary is to call the open
  528.           window routines with this pointer as an argument, and the same
  529.           window which was displayed in MENUGEN will be opened.  The window
  530.           can be modified simply by changing any of the parameters in the
  531.           include file structure.
  532.  
  533.      Window Management
  534.  
  535.           Once a window is open, it can be manipulated by the window
  536.           management functions:
  537.  
  538.                     clear_window()                fill_window()
  539.                     activate()                    move_window()
  540.                     scroll_window()               clear_wndw_title()
  541.                     title_window()
  542.  
  543.           and all of the window printing and cursor control functions.  A
  544.           short synopsis of most of the functions follows.
  545.  
  546.           clear_window()
  547.  
  548.                This function is simply a clear_screen for the currently
  549.                active window.  All the area inside the borders is changed to
  550.                blank characters using the current fill attribute for the
  551.                window.
  552.  
  553.           activate()
  554.  
  555.                All of the open windows are managed by a doubly linked list,
  556.                with the currently active window being the last one in the
  557.                chain.  A window can be made the active window by calling
  558.                activate() with the address of it's window structure as an
  559.                argument.  The window routines will bring that window to the
  560.                top on the screen if any other windows are covering any part
  561.                of it, and the linked list will be updated to show that
  562.                window as being at the end of the list. A global WNDW
  563.  
  564.  
  565.  
  566.                                                                      page 11
  567.  
  568.                pointer, "last_wndw" will be updated to point to the new
  569.                active window. 
  570.  
  571.           title_window()
  572.  
  573.                Allows you to easily insert a title string into the border
  574.                area of a window using any video attribute you like.  It will
  575.                automatically right or left justify or center the string in
  576.                either the top or bottom border, depending on the
  577.                justification code that you supply.
  578.  
  579.           clear_wndw_title()
  580.  
  581.                Removes any titles in either the top or bottom border of a
  582.                window and restores the border characters and attributes as
  583.                defined in the window structure.
  584.  
  585.           fill_window()
  586.  
  587.                fill_window() quickly redraws the interior of a window using
  588.                the default fill character and attribute as defined in the
  589.                window structure.  This function provides an efficient means
  590.                of clearing a window when something other than a space
  591.                character is the fill character.
  592.  
  593.           move_window()
  594.  
  595.                Provides an easy way to move a window's position on the
  596.                screen.  Each call will move the window either left, up,
  597.                right, or down the number of screen character positions
  598.                supplied.  The window will not, however, move past the point
  599.                where one of the borders meets the edge of the screen.
  600.  
  601.           scroll_window()
  602.  
  603.                scrolls the area within the borders of the window either up
  604.                or down, a specified number of lines.  The area cleared by
  605.                the scroll is filled with the current window fill attribute
  606.                defined in the window structure.
  607.  
  608.      Closing Windows
  609.  
  610.           An open window can be closed at any time with a call to
  611.           close_window() using the window structure address or a pointer to
  612.           this address as an argument.  In the example below assume
  613.           that head1 is a structure of type WNDW.
  614.  
  615.  
  616.                                                                      page 12
  617.  
  618.                int ret_code;
  619.                WNDW *wind3;
  620.  
  621.                     wind3 = &head1;
  622.                     ret_code = open_window( wind3 );
  623.                     if(ret_code)
  624.                          printf("\nError opening window\n");
  625.  
  626.                     close_window( wind3 );
  627.  
  628.  
  629.           If the window is not the active window, it is activated to bring
  630.           it to the top of the list. The screen is restored and all the
  631.           links  binding the window to the list are deleted. Finally, the
  632.           memory allocated to the video buffer is freed.
  633.  
  634.  
  635.  
  636.                                                                      page 13
  637.                                   MENUS
  638.  
  639.  
  640.      Creating Menus
  641.  
  642.           Menus, like windows, can easily be added to your programs simply
  643.           by defining three structures and making a call to the menu
  644.           executive function menu().  All of the information needed by
  645.           menu() is in these three structures.  The first is the WNDW
  646.           structure that the menu will occupy. This is a standard window
  647.           structure as described above in the section on windows and
  648.           defines the video area and attributes of the menu.  All screen
  649.           references in the menu are relative to this window, so after a
  650.           menu is defined, it can be moved around the screen simply by
  651.           changing the window position.  This structure is pointed to by
  652.           the menu structure typedef MENU.  MENU describes the cursor type
  653.           and it's default video attributes, the menu title, the number of
  654.           selections in the menu, pointers to default help and error
  655.           functions, the help and exit hot keys, pointers to the menu
  656.           window structure and an array of structures of typedef SEL. 
  657.           Struct SEL defines an individual menu selection.  It contains a
  658.           pointer to the selection text line. The starting column and row
  659.           relative to the menu window where this text will be displayed.
  660.           Video attributes for the selection, if something other than the
  661.           default attributes are to be used.  A pair of activate keys are
  662.           defined which will call the selection without having to use the
  663.           cursor.  A pointer to a help function which you supply can be
  664.           included to provide context sensitive help. Either a pointer to
  665.           the function to be called or a text string to a program name to
  666.           be executed must be provided. The other is set to a NULL. 
  667.           Finally an int value determines if the menu should be exited to
  668.           it's caller after the called function returns or if another
  669.           selection from the menu will be made available.
  670.  
  671.      Menugen 
  672.  
  673.           As you may have deduced from the paragraph above, setting up a
  674.           menu requires entering a lot of information into several complex
  675.           structures.  This would be a tedious task indeed were it not for
  676.           the program MENUGEN.  MENUGEN automates the process of setting
  677.           up a menu, allowing you to interactively build the menu on
  678.           screen, and when completed, it writes a header file containing
  679.           all the necessary structures.  Complete information on the
  680.           running MENUGEN is included in the appendix.
  681.  
  682.      Menu Selections
  683.  
  684.           Selections can be made from the menu either by using the
  685.           activate keys defined for each item in the SEL list or by using
  686.           a bounce bar pseudo cursor.  This cursor highlights the
  687.           selection text with a different video attribute than the non
  688.           selected text.  The cursor is moved from item to item using the
  689.           cursor keys.  The next closest menu item in the direction indicated
  690.           by the cursor arrow is selected.  When the desired item is
  691.           highlighted, pressing the return key runs it's function or
  692.           program.  If the operation to be performed when an item is 
  693.  
  694.  
  695.                                                                      page 14
  696.  
  697.           selected is a function, then the function call is made with the
  698.           index of that item in the array of SEL structures as an
  699.           argument.  This way one function can be used to service several
  700.           similar items, using the argument to determine which selection
  701.           was made.  Three types of pseudo cursors are supported.  One
  702.           highlights the area exactly as long as the selected item. 
  703.           Another highlights an area as long as the longest item in the
  704.           SEL list.  The last highlights the full length of the menu
  705.           window.  The int value pcursor_type in MENU determines which
  706.           type is used and is decoded as follows:
  707.  
  708.                                      0 == String length
  709.                                      1 == Max string length
  710.                                      2 == Full window length
  711.  
  712.  
  713.      Error Handling
  714.  
  715.           All functions called by the menu routine must return an error
  716.           code.  If the call returns without error then a zero should be
  717.           returned.  If any other value is returned, then the error
  718.           function pointed to in the MENU structure is called with that
  719.           error code as an argument.  You can then decode this value and
  720.           take appropriate action.  Pressing an undefined key while in the
  721.           menu calls the error function with an error code of zero.  This
  722.           is usually handled simply by beeping the console speaker and
  723.           returning.
  724.  
  725.  
  726.      menu_text()
  727.  
  728.           A place is provided in the MENU structure for a pointer to a
  729.           function which is called after the menu window is opened, and
  730.           before the selections are written to the screen.  This function
  731.           can be used write descriptive text or otherwise embellish the
  732.           menu's screen.
  733.  
  734.      Titling Menus
  735.  
  736.           A menu title can be defined which will written in the border of
  737.           the menu's window.  Any video attribute can be defined for the
  738.           title and it can be either centered, left justified, or right
  739.           justified in the top or bottom border.  If the length of the
  740.           title string is longer than width of the window, the text is
  741.           truncated to fit.  Positioning of the title is determined by the
  742.           int value title_format in MENU as follows:
  743.  
  744.                                      1 == Upper Left
  745.                                      2 == Upper Center
  746.                                      3 == Upper Right
  747.                                      4 == Lower Left
  748.                                      5 == Lower Center
  749.                                      6 == Lower Right 
  750.  
  751.  
  752.                                                                      page 15
  753.  
  754.  
  755.      Menu Structures
  756.  
  757.         Below is a listing of the structures defined in the header menu.h
  758.                
  759.      typedef struct MENU { 
  760.         struct WNDW *menu_window;    /* Pointer to the menu window structure */
  761.         int   default_non_select_att;/* Usually the same as window fill attr */    
  762.         int   default_cursor_att;    /* Attribute of items when selected     */ 
  763.         int   title_format;          /* Position of menu title on border(1-6)*/
  764.         int   window_title_att;      /* Video attribute of menu title        */
  765.         char  *window_title_text;    /* Pointer to menu title text string    */
  766.         int   pcursor_type;          /* Type of selection cursor (0-2)       */
  767.         int   exit_key;              /* Hot key to exit menu, Usually ESC    */
  768.         int   help_key;              /* Hot key to call help function, if any*/
  769.         int   (*menu_text)();        /* Ptr to function to write text to scrn*/
  770.         int   (*error_fn)();         /* Ptr to user supplied error handler   */
  771.         struct SEL *sel_list;        /* Ptr to the first in array of SELs    */ 
  772.         int   num_sel;               /* Number of menu selections             */   
  773.         }    MENU; 
  774.  
  775.  
  776.     
  777.      typedef struct SEL{ 
  778.         char *text;               /* Pointer to item selection text string  */
  779.         int  start_col;           /* Starting col in window for text string */
  780.         int  start_row;           /* Starting row in window for text string */
  781.         int  sel_att;             /* Item sel video attr, Zero for default  */ 
  782.         int  unsel_att;           /* Item unselected video attribute or Zero*/ 
  783.         int  activate_key_1;      /* First Activate hot key                 */
  784.         int  activate_key_2;      /* Second Activate hot key                */
  785.         int  (*do_function)();    /* Ptr to selected function or NULL       */ 
  786.         char *exe_call;           /* Ptr to program name string or NULL     */ 
  787.         int  (*help_function)();  /* Ptr to optional help fctn or NULL      */ 
  788.         int  exit;                /* exit menu after command, Zero if no    */ 
  789.         } SEL; 
  790.   
  791.  
  792.  
  793.  
  794.                                                                      page 16
  795.                    GLOBAL VARIABLES DEFINED IN TOOLS4C.LIB
  796.  
  797.  
  798.  
  799.           char  *_vid_buf     Is set by vid_type() to point to the segment
  800.                               of the video display buffer.  It is
  801.                               initialized to point to the segment of a
  802.                               monochrome card.  If the current video mode is
  803.                               something other than seven, this is changed to
  804.                               the segment of a color-graphics card.  This
  805.                               value is used by a large number of the screen
  806.                               I/O routines.
  807.  
  808.           int  _vid_type      Is set by vid_type() to reflect what type of
  809.                               video card is being used.  The current video
  810.                               mode is checked and if the mode is seven,
  811.                               _vid_type is set to zero. If any other mode is
  812.                               set, a color/graphics card is assumed and
  813.                               _vid_type is set to 1.  
  814.  
  815.           int  _color         Is set by vid_type() to 1 if the current video
  816.                               mode is set to CO80.  It is set to 0 if the 
  817.                               mode is set to BW80 or MONO.  This variable is
  818.                               used to select between color and monochrome
  819.                               video attributes.
  820.  
  821.           int  _retrace       Is also set by vid_type() to 1 if a
  822.                               color/graphics video board is being used to
  823.                               enable checking for retrace blanking.  Many of
  824.                               the video routines will run much quicker if
  825.                               this is set to zero and you have a video card
  826.                               which allows accessing video memory without
  827.                               generating snow.
  828.  
  829.           char temp_str[256]  This is a global data buffer used by many of
  830.                               the string handling routines.  You can use
  831.                               this area as a temporary data buffer in your
  832.                               own routines as long as you do not make any
  833.                               calls to turbo.lib functions before you are
  834.                               finished with any data that you have stored
  835.                               there.
  836.  
  837.           int   insert_flag   This flag is toggled by the insert key when in
  838.                               get_field to switch between insert
  839.                               (insert_flag == 1) and over_write (insert_flag
  840.                               == 0) modes.
  841.  
  842.           WNDW  *first_wndw   Is a pointer to the first window structure in
  843.                               the linked list of open windows. If there are
  844.                               no windows open it is set to NULL.
  845.  
  846.           WNDW  *last_wndw    Is a pointer to the last window structure in
  847.                               the linked list of open windows. If there are
  848.                               no windows open it is set to NULL, otherwise
  849.                               it always points to the active window.
  850.  
  851.  
  852.                                                                     page 17
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.                              WARRANTY AND DISCLAIMER
  862.  
  863.  
  864.  
  865.                Before registration, there is no warranty whatsoever. 
  866.  
  867.                After you register your copy of TOOLS FOR C, we offer
  868.                you the same limited warranty most software developers
  869.                offer.  That is to say, with the exception of the
  870.                physical media upon which you receive your software,
  871.                there is no warranty ( within 90 days, we will replace
  872.                any bad disks).  We have done our best to provide a
  873.                useful library of C functions, we let you try before
  874.                you buy, and we give you the source code to the
  875.                library.  The complete responsibility for determining 
  876.                whether this library meets your needs, and ensuring
  877.                that any programs developed using any of it's
  878.                functions are bug free and will run as intended rests
  879.                with you, the application programmer. 
  880.  
  881.                That's it, That's all, There ain't no more.
  882.  
  883.  
  884.  
  885.                                                                     page 18
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.                                    INDEX
  894.  
  895.  
  896.  
  897.          activate() . . . . . (10)         Move_window()  . . . (11)         
  898.          Character Output . . ( 5)         Open_ex_window() . . ( 9)       
  899.          clear_window() . . . (10)         Open_window()  . . . ( 9)          
  900.          close_window() . . . (11)         Pseudo cursor()  . . (13)
  901.          Closing Windows  . . (11)         Screen Scrolling . . ( 9)
  902.          Creating Menus . . . (13)         scroll() . . . . . . ( 6)
  903.          Creating Windows . . ( 8)         String Output  . . . ( 9)
  904.          Curs() . . . . . . . ( 5)         struct WNDW  . . . . ( 8)
  905.          Cursor() . . . . . . ( 5)         struct MENU  . . . . (15)
  906.          Cursor Control . . . ( 5)         struct SEL . . . . . (15)
  907.          first_wndw . . . . . (16)         Titling menus  . . . (14)
  908.          Get_cursor() . . . . ( 5)         temp_str . . . . . . (16)
  909.          GLOBAL VARIABLES . . (16)         vid_type() . . . ( 4)(16)
  910.          Identifier Length  . ( 3)         VIDEO  . . . . . . . ( 4)
  911.          insert_flag  . . . . (16)         Video Attributes . . ( 4)
  912.          INTRODUCTION . . . . ( 3)         Video Routines . . . ( 4)
  913.          Key()  . . . . . . . ( 7)         WINDOWS  . . . . . . ( 8)
  914.          KEYBOARD . . . . . . ( 7)         Window Management  . (10)
  915.          KEY.H  . . . . . . . ( 7)         _color . . . . . . . (16)
  916.          last_wndw  . . . . . (16)         _retrace . . . . . . (16)
  917.          Menu() . . . . . . . (13)         _vid_buf . . . . . . (16)
  918.          Menugen.Exe  . . (10)(13)         _vid_type  . . . ( 4)(16)
  919.          MENUS  . . . . . . . (13)                        
  920.         
  921.  
  922.